<?php
namespace app\admin\controller;
use app\admin\model\Outrecord as thisModel;
use app\admin\model\Equipgroup as equipgroupModel;
use think\Db;
use Env;
class Outrecord extends Common
{
    function index(){
        $thisModel = new thisModel();
        $equipgroupModel = new equipgroupModel();
        $mainData = $thisModel->mainData();
        $inputData = input('get.');

        // 分组
        $equipgroup_list = $equipgroupModel->mainAllList();
        $this->assign('equipgroup_list', $equipgroup_list);

     // dump($mainData);exit;
        $this->assign('list',$mainData['list']);
        $this->assign('page',$mainData['page']);
        $this->assign('count',$mainData['count']);
        $this->assign('inputData',$inputData);

        return $this->fetch('index');
    }

    function mainDel(){
        $id = input('id');
        if($id>0){
            $thisModel = new thisModel();
            $one = $thisModel->get($id);
            $res = $one->delete();
            if($res !== false){
                exitjson(1,'删除成功');
            }else{
                exitjson(0,'删除失败');
            }
        }
    }

    function form(){
        $thisModel = new thisModel();
        // $data = $thisModel->disposeData(input('post.'));
        $data['patient_id'] = input('post.patient_id');
        $data['equipgroup_id'] = input('post.equipgroup_id');
        $data['starttime'] = time();

        $equipgroup = Db::name("equip_group")->find($data['equipgroup_id']);
        $minute = $equipgroup['time_min']>0 ? $equipgroup['time_min'] : 0;
        $data['endtime'] = strtotime("+{$minute} minute");

        $res = $thisModel->save($data);
        if($res){
            $this->success('提交成功','Outrecord/index','',0);
        }else{
            $this->error('提交失败','Outrecord/index','',0);
        }

        // if(empty($id)){
        //     $res = $thisModel->save($data);
        //     if($res){
        //         $this->success('添加成功','Outrecord/index','',0);
        //     }else{
        //         $this->error('添加失败','Outrecord/index','',0);
        //     }
        // }else{
        //     $res = $thisModel->save($data,['id'=>$id]);
        //     if($res !== false){
        //         $this->success('编辑成功','Outrecord/index','',0);
        //     }else{
        //         $this->error('编辑失败','Outrecord/index','',0);
        //     }
        // }
    }
}